package com.ww.java8.datetime;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * TODO
 *
 * @author wanggw
 * @date 2024-02-23 23:38:09
 */
public class DateTimeFormatterDemo {

    public static void main(String[] args) {
        LocalDate date = LocalDate.of(2024, 3, 1);

        // 转为字符串
        String s1 = date.format(DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println("s1: " + s1);
        String s2 = date.format(DateTimeFormatter.ISO_LOCAL_DATE);
        System.out.println("s2: " + s2);

//        s1: 20240301
//        s2: 2024-03-01

        // 字符串转为LocalDate
        LocalDate date1 = LocalDate.parse("20240324", DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println("date1: " + date1);
        LocalDate date2 = LocalDate.parse("2024-03-24", DateTimeFormatter.ISO_LOCAL_DATE);
        System.out.println("date2: " + date2);

//        date1: 2024-03-24
//        date2: 2024-03-24
    }
}
